/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/userGroupService.ts" />
/// <reference path="../src/tms.ts" />

describe('getUserGroupService', () => {
    var injector: ng.auto.IInjectorService;
    var service: IUserGroupService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IUserGroupService>('userGroupService');
    });

    //常规无条件获取
    it('get userGroup list normal', (done) => {
        service.getList(null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|0|10");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //获取用户组名称包含 管理层 的用户列表
    it('get userGroup list by name \'管理层\' ', (done) => {
        service.getList('管理层', 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("管理层|0|10");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //获取用户组详情
    it("get detail", (done) => {
        service.getDetail("1").then((res) => {
            expect(res.data.name).toBe("detail");
            expect(res.data.commissionerType.length).toBe(2);
            expect(res.data.roles.length).toBe(2);
            expect(res.data.extData).toBe("1");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //编辑用户组
    it('edit userGroup ', (done) => {
        service.edit("2", "管理", ["2", "3"]).then((res) => {
            expect(res.data.extData).toBe("2|管理|2");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //添加用户组
    it('add userGroup', (done) => {
        service.add("客服", ["1", "2"]).then((res) => {
            expect(res.data.extData).toBe("客服|2");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //删除用户组
    it('delete userGroup', (done) => {
        service.delete("2").then((res) => {
            expect(res.data.extData).toBe("2");
            done();
        }, (err) => {
            done.fail(err);
        });
    });
});